package com.delong.lease.web.app.custom.interceptor;

import com.delong.lease.common.exception.LeaseException;
import com.delong.lease.common.result.ResultCodeEnum;
import com.delong.lease.common.utils.JwtUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @author shangshang
 * @date 2024/10/9 19:39
 */
@Component
public class LoginProtectHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String accessToken = request.getHeader("access_token");
        if (ObjectUtils.isEmpty(accessToken)){
            throw new LeaseException(ResultCodeEnum.ADMIN_LOGIN_AUTH);
        }else {
            JwtUtil.parseToken(accessToken);
        }
        return true;
    }
}
